package com.msb.servicedriveuser.controller;


import com.msb.commons.dto.DriverUser;
import com.msb.commons.response.DriverUserExistsResponse;
import com.msb.commons.response.OrderDriverResponse;
import com.msb.commons.response.ResponseResult;
import com.msb.servicedriveuser.service.DriverUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chshh
 * @since 2022-10-25
 */
@RestController
public class DriverUserController {

    @Autowired
    private DriverUserService driverUserService;

    @PostMapping("/user")
    public ResponseResult addDriverUser(@RequestBody DriverUser driverUser){
        return driverUserService.addDriverUser(driverUser);
    }

    @PutMapping("/user")
    public ResponseResult updateDriverUser(@RequestBody DriverUser driverUser){
        return driverUserService.updateDriverUser(driverUser);
    }

    @GetMapping("/check-driver/{driverPhone}")
    public ResponseResult getDriverUser(@PathVariable("driverPhone") String driverPhone){

        return driverUserService.getDriverUserByPhone(driverPhone);
    }

    /**
     * 根据cityCode查询当前城市是否有可用司机
     * @param cityCode
     * @return
     */
    @GetMapping("/is-available-driver")
    public ResponseResult<Boolean> isAvailableDriver(@Param("cityCode") String cityCode) {
        return driverUserService.isAvailableDriver(cityCode);
    }

    /**
     * 根据车辆id,查询可以派单的司机信息
     * @param carId
     * @return
     */
    @GetMapping("/get-available-driver/{carId}")
    public ResponseResult<OrderDriverResponse> getAvailableDriver(@PathVariable("carId") Long carId) {
        return driverUserService.getAvailableDriver(carId);
    }

}

